﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Clandestine.Battle
{
    public class StatusWindow : Sprite
    {

        private Dictionary<Player, StatusLine> Players = new Dictionary<Player, StatusLine>();
        private AnimatedSprite cursor = new AnimatedSprite();

        public Padding Padding = new Padding(5, 5, 7, 7);

        public StatusWindow(List<Player> players, Point pos)
            : base("battle_status.png")
        {
            base.Position = pos;

            // Setup cursor
            cursor.AddAnimation("bounce", new Animation("rcursor_anim.png", 19, 13, 0, 0, 0, 5));
            cursor.Visible = false;
            cursor.Playing = false;
            cursor.Interval = 100;
            cursor.Layer = 20;

            // Make the sprites
            int lineHeight = Fonts.Default2.Height;
            for (int i = 0; i < players.Count; i++)
            {
                // Make Status Line
                Point p = new Point(this.X + this.Padding.Left, this.Y + this.Padding.Top + (lineHeight * i));
                Players.Add(players[i], new StatusLine(players[i], p)); 

                // Add die event so we can remove.
                //players[i].OnDie += new CombatantDie(OnDie);
            }
        }

        private void OnDie(Combatant c)
        {
            Players[(Player)c].Dispose();
            Players.Remove((Player)c);
        }

        public void ShowCursor(Player p)
        {
            cursor.X = Players[p].Name.X + Players[p].Name.Width;
            cursor.Y = Players[p].Name.Y + (Players[p].Name.Height / 2) - (cursor.UnscaledHeight / 2);
            cursor.Visible = true;
            cursor.Playing = true;
        }

        public void HideCursor()
        {
            cursor.Visible = false;
            cursor.Playing = false;
        }


    }
}
